package com.lh.如何防止重复提交表单;

import sun.misc.Request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "/form",urlPatterns = "/form")
public class Form extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        if (session.getAttribute("token") != "" && session.getAttribute("token") != null) {
            String token = (String) session.getAttribute("token");
            String username = req.getParameter("username");
            String userToken = req.getParameter("token");
            if (token.equals(userToken)) {
                System.out.println("表单提交成功！！");
            }else {
                System.out.println("token 不正确");
            }
            session.setAttribute("token", "");
        }else{
            session.setAttribute("token", "");
            System.out.println("表单不允许重复提交！");
        }
    }
}
